<template>
	<view>
		<view class="mode">
			<view class="">
				提现方式
			</view>

			<view>
				<view class="row">
					<view class="btns" v-for="(item,index) in btnList" :key="index" :class="current==index?'change':''"
						@click="cbtnList(item,index)">
						{{item.moneny}}
					</view>
				</view>

			</view>
		</view>
		
		<view class="mode">
			<view class="">
				可以提现金额({{canPrice}})
			</view>
		
			<view>
			    <u-input placeholder="请输入提现金额" v-model="txPrice" type="Number"></u-input>
			</view>
		</view>
		

		<view class="mode" style="text-align: center;">
			<u-cell-item title="提现账户" value="更改" :border-bottom="false" @click="change"></u-cell-item>
           
		   <view v-if="name&&logo">
			   <view style="margin: 40rpx auto;width: 100rpx;">
			   	<u-image :src="logo" width="100" height="100"></u-image>
			   </view>
			   
			   <view ><text style="color: #628DFF;">{{name}}</text>的{{current?'微信':'支付宝'}}收款码</view>
		   </view>
			


		</view>
		
		
		<u-button shape="circle"
			:custom-style="{background:'#628DFF',color:'#fff',marginTop:'40rpx',width:'500rpx',marginBottom:'40rpx'}"  @click="submit">
			提交提现申请</u-button>
<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnList: [{
					moneny: "提现到支付宝"
				}, {
					moneny: "提现到微信"
				}],
				withdrawMinMoney:"",
				current: 0,
				name: "",
				txPrice:"",
				canPrice:"",
				logo: ''
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.information()
			
		},
		methods: {
			cbtnList(item, index) {
				this.current = index
				this.information()
			},
			change(){
				// id=1支付宝
				// id=2微信
				if(this.current){
					uni.navigateTo({
						url:"uptixian?id=1"
					})
				}else{
					uni.navigateTo({
						url:"uptixian?id=2"
					})
				}
			
			},
			information(){
				this.$u.post('/api/Financial/info', {
					
				}, {}).then(res => {
					this.canPrice=res.data.commission;
					this.withdrawMinMoney=res.data.withdrawMinMoney;
					if(!this.current){
						this.name=res.data.alipayName
						this.logo=res.data.alipayQr	
					}else{
						this.name=res.data.wxName
						this.logo=res.data.wxQr
					}
				
				}).catch(err => {})
			},
			
		    submit(){
			console.log( )
				if(!this.txPrice || this.txPrice<=0 || Number(this.txPrice)>Number(this.canPrice)){
					this.$u.toast("请输入正确金额")
					return false
				}
				if(Number(this.txPrice) < Number(this.withdrawMinMoney)){
					this.$u.toast("提现金额不得少于"+this.withdrawMinMoney)
					return
				}
				
				this.$u.post('/api/Financial/withdraw', {
					money:this.txPrice,
					type:this.current?1:2
				}, {}).then(res => {
					
					this.$refs.uToast.show({
							title: '提交成功',
							type: 'success',
						    
					})
					this.information()
				
				}).catch(err => {})
			},
		}
	}
</script>

<style lang="scss">
	@import 'common.css';

	.row {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		margin-top: 40rpx;
	}

	.btns {
		background: #F7F7F7;
		border-radius: 60rpx;
		text-align: center;
		color: #999999;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		padding: 14rpx 20rpx;
	}

	.change {
		background: #628DFF;
		color: #FFFFFF;
		opacity: 1;
		transition: all 0.3s
	}
</style>
